from engine.strategy import Strategy
from engine.datafeed import CSVDatafeed
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


class MyStrategy(Strategy):
    def __init__(self, feed):
        super(MyStrategy, self).__init__(feed)

    def onbar(self, index, date, df_bar):
        instrument = '000300.SH'
        if index == 0:
            self.acc.order_buy_mv(instrument, 100000)

        se = df_bar.loc[instrument]
        print(se['date'], '\t', se['close'])
        print(self.acc.get_total_mv())


feed = CSVDatafeed()
feed.add_data('000300.SH', '../datas/000300.SH.csv')

s = MyStrategy(feed=feed)
s.run()
s.plot(benchmark=['000300.SH'])  # 需要在feed里加载地数据的
